package com.iris.live.services.servlet;

import com.iris.live.services.services.ApprovalService;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServlet;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

public class TimerServlet extends HttpServlet {

	@Autowired
	private ApprovalService approvalService;

	public TimerServlet() {
		super();
		init();
	}

	public void init() {
		Timer timer = new Timer();
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.MINUTE, 0);
		calendar.set(Calendar.SECOND, 0);

		TimerTask syncTask = new TimerTask() {
			@Override
			public void run() {
				approvalService.autoReleaseDaily();
				approvalService.sendReleaseNotice();
			}
		};
		calendar.set(Calendar.HOUR_OF_DAY, 1);
//		timer.scheduleAtFixedRate(syncTask, calendar.getTime(), 1000 * 60 * 60 * 24);
//		timer.scheduleAtFixedRate(syncTask, 10*1000, 1000 * 60 * 60 * 24);
	}

}
